package com.chenfan.mcn.extension.log;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @author tangwei
 * Date:     2021/1/10 13:43
 * Description: 操作日志类型
 */

@AllArgsConstructor
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum OperationTypeEnum {

    /**
     * 字段变化操作类型
     */

    INSERT(1, "新建"),

    DELETE(2, "删除"),

    UPDATE(3, "修改"),
    ;

    @Getter
    private Integer type;

    @Getter
    private String desc;

    public static boolean isInsert(Integer type) {
        return OperationTypeEnum.INSERT.getType().equals(type);
    }

    public static boolean isDelete(Integer type) {
        return OperationTypeEnum.DELETE.getType().equals(type);
    }


    public static String getDesc(Integer type) {
        if(Objects.nonNull(type)) {
            for (OperationTypeEnum item : OperationTypeEnum.values()) {
                if (item.type.equals(type)) {
                    return item.getDesc();
                }
            }
        }
        return null;
    }
}